  const fs = require("fs");
  const path = require("path");
  const info = require("debug")("log:info");
  const error = require("debug")("log:error");
  const FileStreamRotator = require('file-stream-rotator');
  const iconv = require('iconv-lite');
  const BufferHelper = require('bufferhelper');

  const logDirectory = path.join(__dirname,'logs');
  // 运行日志
  var runningLogStream = FileStreamRotator.getStream({
    filename: logDirectory + '/running-%DATE%.log',
    frequency: 'daily',
    verbose: false
  });
  const log=(content,level='info')=>{
    let time = new Date().toLocaleString();
    var w = `[${level}][${time}]:${content}`;
    runningLogStream.write(w+'\n');
    // var data = new Buffer('嘻嘻嘻kkk');
    // w = iconv.encode(data,'utf8');
    // var iconv = new Iconv( 'UTF-8','GBK');  
    // w =iconv.convert(w).toString(); 
    // w = iconv.decode(data,'win1251'); 
    if(level == 'info'){
      info(w);
    }
    if(level == 'error'){
      error(w);
    }
    console.log(w);
  }
  module.exports = log; 